{extend name="public/base" /}
{block name='body'}
<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" >
            <ul class="layui-tab-title">
                <li><a href="login.html">登入</a></li>
                <li class="layui-this">注册</li>
            </ul>
            <div class="  layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <div class=" layui-form-pane">
                        <div class="layui-form">
                            <div class="layui-form-item">
                                <label for="L_username" class="layui-form-label">用户名</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_username" name="username" required
                                             autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">全站唯一</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_email" class="layui-form-label">邮箱</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_email" name="Email"  lay-verify="email"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">用来找回密码</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="password" required
                                            autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_repass" class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_repass" name="repassword" required
                                            autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_vercode" class="layui-form-label">验证码</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_vercode" name="vercode" required lay-verify="required"
                                           placeholder="" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid">
                                     <span style="color: #c00;">
    <div class="sw-verify-img">
        <img src="{:url('base/vercode','id=reg')}" onclick="this.src=this.src+'?'+Math.random()">
    </div>
</span>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-submit lay-filter="reg">立即注册</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['jquery', 'layer', 'form'], function () {
        let layer = layui.layer, $ = layui.jquery, form = layui.form;
        form.on('submit(reg)', function (obj) {
            let data = obj.field;
            let vercode = data.vercode;
            if (data.password !== data.repassword) {
                layer.alert('两次输入的密码不一致');
                return $("input[type='password']").val('');
            }
            let load = layer.load();
            $.post("{:url('login/checkVercode')}", {code: vercode, id: 'reg'}, function (res) {
                layer.close(load);
                if (res.errno === 0) {
                    //继续
                    $.post("{:url('login/regApi')}", data, function (res) {
                        if (res.errno === 0) {
                            layer.alert('注册成功', function () {
                                location.href = "{:url('login/login')}";
                            });
                        } else {
                            layer.alert(res.errmsg);
                        }
                    });
                } else {
                    return layer.msg(res.errmsg);
                }
            });
        })

    });
</script>
{/block}